const DATA = {
  baseElements: [
    { type: "text", name: "文本", value: "这是文本" },
    { type: "textInput", name: "输入文本", placeholder: "输入文本" },
    { type: "numberInput", name: "输入数字", placeholder: "输入数字" },
    { type: "select", name: "选择", opts: "1 2 3" },
    { type: "switch", name: "开关", value: false },
    { type: "pressureSwitch", name: "压力开关", value: false },
    { type: "idSelect", name: "外键选择", value: "选择外键" },
  ],
  schemaPropMap: {
    id: "TEXT",
    name: "TEXT",
    value: "TEXT",
    opts: "TEXT",
    placeholder: "TEXT",
    tableName: "TEXT",
    show: "TEXT",
    other: "TEXT",
    //crypt: "BOOLEAN",
    crypt: "TEXT",
    required: "TEXT",
  },
  schemaMap: {
    id: "INTEGER PRIMARY KEY AUTOINCREMENT",
    select: "TEXT",
    text: "TEXT",
    textInput: "TEXT",
    switch: "TEXT",
    pressButton: "TEXT",
    number: "INTEGER",
    numberInput: "INTEGER",
    date: "INTEGER",
    other: "TEXT",
    //required: "TEXT CHECK(required105 IS NOT NULL)",
    // sqlite3 not support!!!
    // crypt: {
    //   type: "TEXT",
    //   notNull: true,
    //   set(val) {
    //     return bcrypt.hashSync(val, 10);
    //   },
    // },
  },
  personInfoMap: {
    name: "textInput100",
    account: "textInput101",
    password: "textInput102",
    phone: "numberInput103",
    identify: "select104",
  },
};

const tableNeeded = {
  AppFormula: {
    tableName: "AppFormula",
    schemas: Object.keys(DATA.schemaPropMap),
    data: [
      {
        name: "tableName",
        id: "text100",
      },
      {
        name: "whenUpdate",
        id: "select101",
        value: "auto",
        opts: "auto onSubmit",
      },
      {
        name: "formulaText",
        id: "text102",
      },
    ],
  },
  personInfo: {
    tableName: "personInfo",
    schemas: Object.keys(DATA.schemaPropMap),
    data: [
      {
        name: "name",
        id: "textInput100",
        required: true,
        // required , send this prop to web handle when user input
      },
      {
        name: "account",
        id: "textInput101",
        required: true,
      },
      {
        name: "password",
        id: "textInput102",
        value: "123456",
        crypt: true,
        // passwords need hash ,use bcrypt
      },
      {
        name: "phone",
        id: "numberInput103",
      },
      {
        name: "identity",
        id: "select104",
        opts: "user admin superAdmin",
        value: "user",
      },
    ],
    _data: {
      tableName: "personInfo_data",
      schemas: [
        "textInput100", //name
        "textInput101", //account
        "textInput102", //password
        "numberInput103", //phone
        "select104", //identity
      ],
      data: [
        {
          textInput100: "user1",
          textInput101: "17112345678",
          textInput102: "h",
          select104: "user",
        },
        {
          textInput100: "admin1",
          textInput101: "17212345678",
          textInput102: "h",
          select104: "admin",
        },
        {
          textInput100: "superAdmin1",
          textInput101: "17312345678",
          textInput102: "h",
          select104: "superAdmin",
        },
      ],
    },
  },
};

DATA.tableNeeded = tableNeeded;
module.exports = DATA;
